//---------------------------------------------------------------------
// File: ConcurrentTestStepWrapper.cs
// 
// Summary: 
//
//---------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, WHETHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
// PURPOSE.
//---------------------------------------------------------------------

namespace Microsoft.Services.BizTalkApplicationFramework.BizUnit
{
	using System;
	using System.Xml;

	/// <summary>
	/// Summary description for ConcurrentTestStepWrapper.
	/// </summary>
	internal class ConcurrentTestStepWrapper
	{
		private ITestStep step;
		private XmlNode stepConfig;
		private Context context;
		private string name;
		private Logger logger;
		private Exception ex;
        private bool failOnError;

		public ConcurrentTestStepWrapper(	ITestStep		step, 
											XmlNode			stepConfig, 
                                            Context         ctx,
											string			name,
                                            bool            failOnError )
		{
			this.step = step;
			this.stepConfig = stepConfig;
            this.logger = new Logger(true);
            this.context = ctx.CloneForConcurrentUse(this.logger);
			this.name = name;
            this.failOnError = failOnError;
		}

		public string Name
		{
			get 
			{
				return this.name;
			}
		}

        public bool FailOnError
        {
            get
            {
                return this.failOnError;
            }
        }

		public Exception FailureException
		{
			get
			{
				return this.ex;
			}
		}

		public void Execute()
		{
			try
			{
				this.logger.WriteLine(string.Format("\nStep: {0} started @ {1} (Concurrent Execution Mode defined)", name, BizUnit.GetNow() ));
				this.step.Execute(this.stepConfig, this.context);
			}
			catch(Exception e)
			{
				this.logger.LogException( e );
				this.ex = e;
			}
		}

		public string GetLogText()
		{
			return this.logger.GetLogText();
		}
	}
}
